package com.ruoyi.web.controller.tongban;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tongban.domain.InsClass;
import com.ruoyi.tongban.service.IInsClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 班级Controller
 * 
 * @author caiyanshan
 * @date 2021-03-09
 */
@RestController
@RequestMapping("/tongban/class")
public class InsClassController extends BaseController
{
    @Autowired
    private IInsClassService insClassService;

    /**
     * 查询班级列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:class:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsClass insClass)
    {
        startPage();
        List<InsClass> list = insClassService.selectInsClassList(insClass);
        return getDataTable(list);
    }
    
    @GetMapping("/listInstitutionClass")
    public AjaxResult listInstitutionClass(@RequestParam Long id)
    {
        List<InsClass> list  = insClassService.listInstitutionClass(id);
        return AjaxResult.success(list);
    }

    /**
     * 导出班级列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:class:export')")
    @Log(title = "班级", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(InsClass insClass)
    {
        List<InsClass> list = insClassService.selectInsClassList(insClass);
        ExcelUtil<InsClass> util = new ExcelUtil<InsClass>(InsClass.class);
        return util.exportExcel(list, "class");
    }

    /**
     * 获取班级详细信息
     */
    @PreAuthorize("@ss.hasPermi('tongban:class:query')")
    @GetMapping(value = "/{classId}")
    public AjaxResult getInfo(@PathVariable("classId") Long classId)
    {
        return AjaxResult.success(insClassService.selectInsClassById(classId));
    }

    /**
     * 新增班级
     */
    @PreAuthorize("@ss.hasPermi('tongban:class:add')")
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsClass insClass)
    {
        return toAjax(insClassService.insertInsClass(insClass));
    }

    /**
     * 修改班级
     */
    @PreAuthorize("@ss.hasPermi('tongban:class:edit')")
    @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsClass insClass)
    {
        return toAjax(insClassService.updateInsClass(insClass));
    }

    /**
     * 删除班级
     */
    @PreAuthorize("@ss.hasPermi('tongban:class:remove')")
    @Log(title = "班级", businessType = BusinessType.DELETE)
	@DeleteMapping("/{classIds}")
    public AjaxResult remove(@PathVariable Long[] classIds)
    {
        return toAjax(insClassService.deleteInsClassByIds(classIds));
    }
}
